home *** CD-ROM | disk | FTP | other *** search
/ Ian & Stuart's Australian Mac 1993 September / September 93.iso / Archives / Utilities / System / FKey / FKeys / Quickeys / project switch.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-10-22  |  3.3 KB  |  118 lines  |  [TEXT/QED1]

  1. /*
  2.   * ProjectSwitch:        FKEY that works with QuicKeys to automate project switching for multiple project
  3.   *                    environments. It puts the name of the current project into a QuicKey text key.
  4.   *                    This can be used as a form of parameter substitution for sequences.
  5.   *                    The key chosen is Cmd-Option-Shift 1.
  6.   */
  7.  
  8.  
  9. #include    <MacTypes.h>
  10. #include    <MemoryMgr.h>
  11. #include    <EventMgr.h>
  12. #include    <WindowMgr.h>
  13. #include    <SegmentLdr.h>
  14. #include    "QuicKeys.h"
  15.  
  16. #define    NULL        0L
  17.  
  18. /* Forward references */
  19. QuicInitBlock    *FindSysHeap();
  20. Boolean        UpdateParamKey(QuicInitBlock *qb, StringHandle theText, int param);
  21.  
  22. pascal void
  23. main()
  24. {
  25.     register WindowPeek        wp;
  26.     register QuicInitBlock     *qb;
  27.  
  28.     /* Have to be running Lightspeed C */
  29.     if (IUCompString(CurApName, "\pLightspeedCâ„¢") != 0) {
  30.         SysBeep(1);
  31.         return;
  32.     }
  33.  
  34.     if ((qb = FindSysHeap()) == NULL) {
  35.         SysBeep(1);
  36.         return;
  37.     }
  38.  
  39.     /*
  40.       * Search the window list for the project window. This search relies on Lightspeed C internals
  41.       * deduced via TMON - namely: document windows have a windowKind of 0xB, and the project
  42.       * window has one of 0xA.
  43.       */
  44.     for (wp = WindowList; wp != NULL; wp = wp->nextWindow) {
  45.         if (wp->windowKind == 0xA) {                /* A project window */
  46.             /* wp->titleHandle is a StringHandle to the window title. This corresponds to the
  47.               * project name. So we search for the reserved key record (type QK_TEXT,
  48.               * key 1, modifiers (Cmd,Option,Shift). When found, we copy in the required
  49.               * title.
  50.               */
  51.             if (UpdateParamKey(qb, wp->titleHandle, 1) == FALSE) SysBeep(1);
  52.             return;
  53.         }
  54.     }
  55. }
  56.  
  57.  
  58. /*
  59.   * This is a  C version of the example code in Chapter 8 of the QuicKeys manual.
  60.   */
  61.  
  62. QuicInitBlock *
  63. FindSysHeap()
  64. {
  65.     register Ptr            endBlk = SysZone->bkLim;
  66.     register QuicInitBlock    *qp;
  67.     
  68.     qp = (QuicInitBlock *) &SysZone->heapData;
  69.  
  70.     while(qp != (QuicInitBlock *) endBlk) {
  71.         /* Analyze the block we're looking at. */
  72.         if ((qp->header[0] & 0xC0) == 0x40) {                /* Is it non-relocatable? */
  73.             /* Check magic and signature. */
  74.             if (qp->quic.magic == 0xa89f1234 && qp->quic.signature == 'CELN') {
  75.                 /* Chapter 8 states that the version number is 1. It's actually 0 (as the example
  76.                   * assembly language shows and a quick call to CE Software confirmed).
  77.                   */
  78.                 if (qp->quic.version == 0) return qp;
  79.             }
  80.         }
  81.  
  82.         /* Time to move on to the next block. The 0xFFFFFF strips off the tag byte(s). */
  83.         qp = (QuicInitBlock *)(((Byte *)qp) + ((* (long *)&qp->header) & 0xFFFFFF));
  84.     }
  85.     return NULL;        /* Failed to find it */
  86. }
  87.  
  88. /*
  89.   * Cmd-Shift-Option 1 through 4 are reserved as parameter records of type 'text' (prog-specific).
  90.   * This routine searches for the given record and copies in the text.
  91.   */
  92.  
  93. Boolean
  94. UpdateParamKey(qb, theText, param)
  95. QuicInitBlock    *qb;
  96. StringHandle    theText;
  97. int            param;
  98. {
  99.     register KeyRecord    *kr = qb->quic.application;
  100.     register KeyRecord    *end = kr + N_QCKEYS;
  101.     register unsigned    key;
  102.  
  103.     /* This depends on the fact that keys 1 through 4 have consecutive keycode values. The charcode values
  104.       * were found by experimentation.
  105.       */
  106.     key = ((0x11 + param) << 8) + 0xD9 + param;        /* Convert to keycode & charcode */
  107.  
  108.     for (; kr < end; kr++) {
  109.         if (kr->QKtype == QK_TEXT) {
  110.             if ((kr->key) == key && (kr->modifiers == (cmdKey|optionKey|shiftKey))) {
  111.                 BlockMove(*theText, kr->u.QuicText.text, (Size)((*theText)[0] + 1));
  112.                 return TRUE;
  113.             }
  114.         }
  115.     }
  116.     return FALSE;
  117. }
  118.